package com.forum.post.client;

import com.forum.post.dto.AuditFeedbackDTO;
import com.forum.post.dto.AuditRequestDTO;
import com.forum.post.dto.AuditResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Collections;

@Slf4j
@Component
public class AutoAuditClientFallbackFactory implements FallbackFactory<AutoAuditClient> {
    
    @Override
    public AutoAuditClient create(Throwable cause) {
        return new AutoAuditClient() {
            @Override
            public AuditResultDTO auditContent(AuditRequestDTO request) {
                log.error("调用自动审核服务失败: {}", cause.getMessage(), cause);
                return AuditResultDTO.builder()
                        .postId(request.getPostId())
                        .auditResult("REVIEW")  // 降级为人工审核
                        .confidence(0.5)
                        .reasons(Collections.singletonList("审核服务暂时不可用"))
                        .suggestion("由于审核服务不可用，需要人工审核")
                        .build();
            }

            @Override
            public void submitFeedback(AuditFeedbackDTO feedback) {
                log.error("提交审核反馈失败: {}", cause.getMessage(), cause);
                // 静默失败，不影响主流程
            }
        };
    }
} 